home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / misc / rangecite.sty < prev    next >
Text File  |  1992-08-30  |  3KB  |  76 lines

  1. % RANGECITE DOCUMENT-STYLE OPTION FOR ANY STYLE WITH NUMERIC CITATIONS
  2. %
  3. % This redefines the LaTex \@cite macro to gather consecutive citation numbers
  4. % i,i+1,...,j into a range i-j
  5. % Nachum Dershowitz (nachum@cs.uiuc.edu)
  6. % Edward M. Reingold (reingold@cs.uiuc.edu)
  7. %
  8. % These macros are in the public domain.  You may use them and copy them at
  9. % will, provided you retain the authorship information.  We wrote these for
  10. % temporary use in a single paper, so use them at your own risk!
  11. %
  12. % Written 12 Apr 1990
  13. %
  14. %
  15. \newif\if@first%
  16. \newcounter{@@@first}%
  17. \newcounter{@@@state}%
  18. %
  19. %  A simple four-state finite automaton:
  20. %        State 0:  No references in current range
  21. %        State 1:  One reference in current range
  22. %        State 2:  Two references in current range
  23. %        State 3:  More than two references in current range
  24. %
  25. \newcounter{@@@next}%
  26. \newcounter{@@@cur}%
  27. \newcounter{@@@curt}%
  28. \newcommand{\b@@@ENDLIST}{9999}%
  29. \def\@citex[#1]#2{%
  30.   \if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
  31.   \def\@citea{}%
  32.   \@cite{%
  33.      \@firsttrue%
  34.      \setcounter{@@@state}{0}%
  35.      \@for\@citeb:=#2,@@ENDLIST\do{%
  36.          \@ifundefined{b@\@citeb}%
  37.             {{\bf ?}%
  38.              \@warning{Citation `\@citeb' on page \thepage \space undefined}}%
  39. %        else%
  40.             {\setcounter{@@@next}{\csname b@\@citeb\endcsname}%
  41.              \ifcase\the@@@state%
  42. %                  state 0:
  43.                \setcounter{@@@state}{1}%
  44.              \or%  state 1:
  45.                \ifnum\value{@@@next}=\value{@@@curt}%
  46.                   \setcounter{@@@state}{2}%
  47.                   \setcounter{@@@first}{\value{@@@cur}}%
  48.                \else%
  49.                   \if@first{}\else{,\ }\fi%
  50.                   \the@@@cur%
  51.                   \@firstfalse%
  52.                \fi%
  53.              \or%  state 2:
  54.                \ifnum\value{@@@next}=\value{@@@curt}%
  55.                   \setcounter{@@@state}{3}%
  56.                \else%
  57.                   \setcounter{@@@state}{1}%
  58.                   \if@first{}\else{,\ }\fi%
  59.                   \the@@@first,\ \the@@@cur%
  60.                   \@firstfalse%
  61.                \fi%
  62.              \or%  state 3:
  63.                \ifnum\value{@@@next}=\value{@@@curt}%
  64.                \else%
  65.                   \setcounter{@@@state}{1}%
  66.                   \if@first{}\else{,\ }\fi%
  67.                   \the@@@first-\the@@@cur%
  68.                   \@firstfalse%
  69.                \fi%
  70.             \fi%
  71.          \setcounter{@@@cur}{\value{@@@next}}%
  72.          \setcounter{@@@curt}{\value{@@@cur}}%
  73.          \addtocounter{@@@curt}{1}}}}%
  74.   {#1}}%
  75.